home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Animation
/
Animation Vol.1 (Profi ROM)(1994).iso
/
pool
/
updates
/
symantec
/
rtlinc.exe
/
IOSTREAM.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-10
|
43KB
|
1,194 lines
// IOStreams Package
// Steve Teale April 1992
// Copyright Symantec Corp 1990-1992. All Rights Reserved.
#ifndef __IOSTREAM_H
#define __IOSTREAM_H
#include <stddef.h>
#include <2comp.h>
#define seek_dir relative_to
#ifndef EOF
const int EOF = -1;
#endif
const int _ios_default_decimal_precision = 6;
const int _ios_n_extended_format_words = 10;
// This is the number of extended format state words reserved for use
// by derived classes and user inserters. This value should be reasonably
// small, as it inflates the size of each instance of ios.
#pragma pack(__DEFALIGN)
class streampos {
friend class streamoff;
public:
streampos(long elems, size_t elemsize = 1) : ne(elems), es(elemsize) {}
operator long() const { return (ne == -1)? EOF: ne*es; }
private:
long ne;
size_t es;
};
class streamoff {
public:
streamoff(long elems, size_t elemsize = 1) : ne(elems), es(elemsize) {}
streamoff(streampos &a) : ne(a.ne), es(a.es) {}
size_t stepsize() const { return es; }
long steps() const { return ne == -1? 0: ne; }
streamoff& operator += (long o) { ne += o; return *this; }
streamoff& operator -= (long o) { ne -= o; return *this; }
operator long() const { return steps()*es; }
private:
long ne;
size_t es;
};
class streambuf;
class ostream;
class istream;
class ios {
// This is the base class for istream and ostream, and all of their
// derivations.
friend ostream &endl(ostream &);
public:
enum io_state {
goodbit=0,
// No errors - everything hunky dory!
eofbit=1,
// Normally set when underflow failed because there was no more file.
failbit=2,
// An error has ocurred, but it is probably recoverable, and the
// stream is still in a useable state
badbit=4
// A fatal error has ocurred
};
// This is called seek_dir in the AT & T version, which is misleading.
// A define is included above for compatibility. These enumerators are
// used to specify relative seeks in streams.
enum relative_to {
beg,
// For seek operations relative to the beginning of the stream (file),
cur,
// relative to the current position in the stream (file),
end
// and relative to the end of the stream (file)
};
// The following enumeration applies to file related derivatives.
enum open_mode {
in=0x1,
// Input allowed
out=0x2,
// Output allowed
ate=0x4,
// A seek to the end of the file to be performed during open.
app=0x8,
// All writes are to the end of the file - implies out
trunc=0x10,
// Existing contents of the file to be discarded. Implies out
// unless ate or app specified as well.
nocreate=0x20,
// Open will fail if the file does not already exist
noreplace=0x40,
// Open will fail if the file does already exist
translated = 0x80
// CR/LF pairs to be translated to newline characters on input
// and newline characters to be translated to CR/LF pairs on
// output (the normal behaviour for DOS)
};
// The formatting state is a bit-mask used to control some of the
// inserters and extractors. All of the bits of the format state
// can be manipulated by flags(), setf(), and unsetf(). Some
// specialized parts of the formatting state can be manipulated
// by fill(), width(), and precision() . Here are the meanings
// of the various bits:
enum format_mode {
skipws = 0x1,
// Skip past leading white space when extracting.
// Since zero-width fields are considered an
// error by the numeric extractors, attempting
// to extract white-space into a number without
// this bit set will set an error flag.
left = 0x2,
// Left-adjust values when inserting (fill on the right).
right = 0x4,
// Right-adjust values when inserting (fill on the left).
internal = 0x8,
// When inserting, fill _between_ the numeric sign or
// base indicator and the value.
dec = 0x10, oct = 0x20, hex = 0x40,
// Default radix for integers. If neither dec, octal,
// or hex is set, integer inserters use base 10, and
// integer extractors interpret numbers according to the
// C++ lexical convention: "0x" precedes a base-16 number,
// and a number with a leading zero is base-8.
showbase = 0x80,
// If this is set, base-16 numbers will be inserted with a
// leading "0x", and base-8 numbers will have a leading zero.
showpoint = 0x100,
// If this is set, the floating-point inserters will print a
// decimal point and trailing zeroes, even when the trailing
// places are not significant.
uppercase = 0x200,
// If this is set, "E" instead of "e" will be used to indicate
// the exponent of a floating point number, and "A" through "F"
// will be used to represent base-16 numerals instead of "a"
// through "f".
//
// If uppercase and showbase are both set, the string "0X"
// instead of "0x" will be used to indicate a base-16 number.
showpos = 0x400,
// If this is set, positive numbers will be inserted with a
// leading "+".
scientific = 0x800,
// If this is set, the floating-point inserters will print a
// number with one digit before the decimal point, and the
// number of digits after the decimal point equal to the
// value of precision(). The character "e" will introduce the
// exponent.
fixed = 0x1000,
// If this is set, the floating-point inserters will use
// precision() to determine the number of digits after the
// decimal point.
//
// If neither scientific or fixed is set, numbers with
// exponents smaller than -4 or greater than precision() will
// be printed as if scientific were set. Other numbers will
// be printed using zeroes to explicitly show the decimal place.
unitbuf = 0x2000,
// When this is set, a flush is performed after each insertion
// (by ostream::osfx()). This is more efficient than using
// unbuffered output, but provides most of the same advantages.
stdio = 0x4000
// When this is set, streams using stdiobufs will flush stdout and
// stderr after each insertion.
// Note that it is not possible to use bit 0x8000 in this way,
// as this evaluates to an enumerator with a negative value and
// lots of bits set.
}; // end enum format_mode
static const long stickywidth;
static const long spacing;
enum format_mode_mask {
defaults = right|skipws,
basefield = dec|oct|hex,
adjustfield = left|right|internal,
floatfield = scientific|fixed
};
public: // just a reminder!
ios(streambuf *buffer);
// Construct an ios associated with the argument streambuf.
// "buffer" should not be null.
virtual ~ios();
/////////////////////////////////////////////////////////////
//
// Functions to interrogate/set the error state
int good() const { return error_state == 0; };
// If there are no error bits set, this returns non-zero, otherwise
// it returns zero.
int eof() const { return error_state & eofbit; };
// If eofbit is set in the error state, this return non-zero, otherwise
// it returns zero. This indicates that end-of-file has been reached
// while reading the character stream.
int fail() { return error_state & (badbit | failbit); }
// If badbit or failbit is set in the error state, return non-zero.
// Otherwise, return zero. Failbit generally indicates that some
// extraction has failed, but the stream may still be used once
// failbit has been cleared.
int bad() const { return error_state & badbit; }
// Returns non-zero if badbit is set in the error state. This
// indicates some unrecoverable error, generally an I/O error.
int operator!() const
{
return error_state & (badbit|failbit);
}
// Return non-zero if badbit or failbit is set in the error state,
// which allows expressions of the form:
// if ( !cout )
operator void*()
{
return (error_state & (badbit|failbit))?
0: this;
}
// Convert an ios to a value th